package com.marquis.cloud.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marquis.cloud.config.pagequery.PaginationGrid;
import com.marquis.cloud.entity.AutUser;
import com.marquis.cloud.mapper.AutUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AutUserService {

    @Autowired
    private AutUserMapper userMapper;

    public List<AutUser> findAll() {
        return userMapper.findAll();
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    public PaginationGrid<AutUser> queryUserPage(PaginationGrid<AutUser> page) {
        PageHelper.startPage(page.getPage(), page.getPageSize());
        List<AutUser> list = userMapper.findAll();
        PageInfo<AutUser> pageInfo = new PageInfo<AutUser>(list);
        page.setTotal(pageInfo.getTotal());
        page.setRows(pageInfo.getList());
        return page;
    }

    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    public AutUser findByUserName(String userName) {
        return userMapper.findByUserName(userName);
    }
}
